package com.kfm.pm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo01 {

    public static void main(String[] args) {
        // catch 不一定被执行 finally 不管有没有异常一定会被执行,
        // try-catch  try -finally  try-catch-finally
        // finally 不被执行的唯一情况是 执行了System.exit(1) 退出虚拟机
        try {
            int i = 1, j = 0, res;
            System.out.println("begin");
            res = i / j;
            String str = "2023-08-20";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = sdf.parse(str);
            System.out.println(parse);
            System.out.println("end");
        } catch (ArithmeticException e) {
            System.out.println("caught");
            e.printStackTrace();
        } catch (ParseException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }finally {
            System.out.println("finally");
        }
        System.out.println("over");
    }

    // try - catch
    // try-catch-finally
    // try-catch-catch-catch...-finally
    // 访问修饰符 返回值类型 方法名(参数列表) throws 异常类型{方法体}
}
